package com.example.permissionsystem1_1.businessFunction.controller.converter;

import com.example.permissionsystem1_1.businessFunction.controller.entity.reqDto.departmentUserReqDto.DepartmentUserSelectAllDepartmentsByUserIdReqDto;
import com.example.permissionsystem1_1.businessFunction.controller.entity.reqDto.departmentUserReqDto.DepartmentUserSetDepartmentUserRelationReqDto;
import com.example.permissionsystem1_1.businessFunction.controller.entity.reqDto.userRoleReqDto.UserRoleSelectAllRolesByUserIdReqDto;
import com.example.permissionsystem1_1.businessFunction.controller.entity.reqDto.userRoleReqDto.UserRoleSetUserRoleRelationReqDto;
import com.example.permissionsystem1_1.businessFunction.controller.entity.rspDto.departmentUserRspDto.DepartmentUserRspDto;
import com.example.permissionsystem1_1.businessFunction.controller.entity.rspDto.departmentUserRspDto.DepartmentUserSelectAllDepartmentsByUserIdRspDto;
import com.example.permissionsystem1_1.businessFunction.controller.entity.rspDto.departmentUserRspDto.DepartmentUserSetDepartmentUserRelationRspDto;
import com.example.permissionsystem1_1.businessFunction.controller.entity.rspDto.userRoleRspDto.UserRoleRspDto;
import com.example.permissionsystem1_1.businessFunction.controller.entity.rspDto.userRoleRspDto.UserRoleSelectAllRolesByUserIdRspDto;
import com.example.permissionsystem1_1.businessFunction.controller.entity.rspDto.userRoleRspDto.UserRoleSetUserRoleRelationRspDto;
import com.example.permissionsystem1_1.businessFunction.service.entity.reqModel.departmentUserReqModel.DepartmentUserSelectAllDepartmentsByUserIdReqModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.reqModel.departmentUserReqModel.DepartmentUserSetDepartmentUserRelationReqModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.reqModel.userRoleReqModel.UserRoleSelectAllRolesByUserIdReqModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.reqModel.userRoleReqModel.UserRoleSetUserRoleRelationReqModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.departmentUserRspModel.DepartmentUserRspModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.departmentUserRspModel.DepartmentUserSelectAllDepartmentsByUserIdRspModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.departmentUserRspModel.DepartmentUserSetDepartmentUserRelationRspModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.userRoleRspModel.UserRoleRspModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.userRoleRspModel.UserRoleSelectAllRolesByUserIdRspModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.userRoleRspModel.UserRoleSetUserRoleRelationRspModel;
import com.example.permissionsystem1_1.common.businessFunction.BaseControllerConverter;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

public class UserRoleControllerConverter extends BaseControllerConverter {
    //1.根据用户id查询全部角色信息
    public static UserRoleSelectAllRolesByUserIdReqModel convertDtoToModel(UserRoleSelectAllRolesByUserIdReqDto reqDto) {
        if(reqDto==null || reqDto.getUserId()==null){
            return null;
        }
        UserRoleSelectAllRolesByUserIdReqModel reqModel=new UserRoleSelectAllRolesByUserIdReqModel();
        BeanUtils.copyProperties(reqDto, reqModel);
        return reqModel;
    }
    public static UserRoleSelectAllRolesByUserIdRspDto convertModelToDto(UserRoleSelectAllRolesByUserIdRspModel rspModel){
        if (rspModel == null) {
            return null;
        }
        UserRoleSelectAllRolesByUserIdRspDto rspDto=new UserRoleSelectAllRolesByUserIdRspDto();
        if(rspModel.getUserRoleRspModels()!=null&&rspModel.getUserRoleRspModels().size()>0){
            List<UserRoleRspDto> userRoleRspDtos=new ArrayList<>();
            List<UserRoleRspModel> userRoleRspModels=rspModel.getUserRoleRspModels();
            for (UserRoleRspModel userRoleRspModel:userRoleRspModels) {
                UserRoleRspDto userRoleRspDto=new UserRoleRspDto();
                BeanUtils.copyProperties(userRoleRspModel, userRoleRspDto);
                userRoleRspDtos.add(userRoleRspDto);
            }
            rspDto.setUserRoleRspDtos(userRoleRspDtos);
        }
        return rspDto;
    }
    //2.设置用户与角色的关联关系
    public static UserRoleSetUserRoleRelationReqModel convertDtoToModel(UserRoleSetUserRoleRelationReqDto reqDto) {
        if(reqDto==null || reqDto.getUserId()==null || reqDto.getRoleIds()==null || reqDto.getRoleIds().size()<=0){
            return null;
        }
        UserRoleSetUserRoleRelationReqModel reqModel=new UserRoleSetUserRoleRelationReqModel();
        BeanUtils.copyProperties(reqDto, reqModel);
        return reqModel;
    }
    public static UserRoleSetUserRoleRelationRspDto convertModelToDto(UserRoleSetUserRoleRelationRspModel rspModel){
        if (rspModel == null) {
            return null;
        }
        UserRoleSetUserRoleRelationRspDto rspDto=new UserRoleSetUserRoleRelationRspDto();
        BeanUtils.copyProperties(rspModel, rspDto);
        return rspDto;
    }


}
